package test;

import java.util.*;

interface GeneralStack<T>{
    public T push(T item);
    public T pop();
    public T peek();
    public boolean empty();
    public int size();
}

class ArrayListGeneralStack<T> implements GeneralStack<T>{
    List<T> list = new ArrayList<T>();
    public T push(T item){
        if(item==null)
            return null;
        list.add(item);
        return item;
        
    }
    public T pop(){
        if(list.isEmpty())
            return null;
        T a= list.get(list.size()-1);
        list.remove(list.get(list.size()-1));
        return a;
    }
    public T peek(){
        if(list.isEmpty())
            return null;
        return list.get(list.size()-1);
    }
    public boolean empty(){
        return list.isEmpty();
    }
    public int size(){
        return list.size();
    }
    public String toString() {
        return list.toString();
    }
    
}

class Car{
    private int id;
    private String name;
    
	public Car(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}

	public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return "Car [id=" + id + ", name=" + name + "]";
    }
    
}

enum Choice{quit, Integer, Double, Car};
public class Main {
    public static void main(String[] args) {
	    Choice choice;
	    Scanner in = new Scanner(System.in);
	    while(in.hasNextLine()){
	    	String str = in.nextLine();
		    if (str.equals("quit"))
		    	System.exit(0);
		    	
		    else{
		    		int m = Integer.parseInt(in.nextLine());
		    		int n = Integer.parseInt(in.nextLine());
		    		if(str.equals("Integer"))
		    			choice = Choice.Integer;
		        	else if(str.equals("Double"))
		        		choice = Choice.Double;
		        	else 
		        		choice = Choice.Car;
		    		ArrayListGeneralStack stack = new ArrayListGeneralStack();
		    	 switch (choice) {
		
		    		case Integer:
		    				System.out.println("Integer Test");
		    				
		    				for (int i = 0; i < m; i++) {
		    					Integer b = in.nextInt();
		    					System.out.println("push:"+stack.push(b));
		    				}
		    				for (int i = 0; i < n; i++) {
		    					System.out.println("pop:"+stack.pop());
		    				}
		    				System.out.println(stack.toString());
		    				Integer x = 0;
							while (!stack.empty()) {
								x += (Integer)stack.pop();
							}
							System.out.println("sum="+x);
		    				System.out.println(stack.getClass().getInterfaces()[0]);
		    			break;
		    		case Double:
		    			System.out.println("Double Test");
		    			for (int i = 0; i < m; i++) {
							Double b = in.nextDouble();
							System.out.println("push:"+stack.push(b));
						}
						for (int i = 0; i < n; i++) {
							System.out.println("pop:"+stack.pop());
						}
						System.out.println(stack.toString());
						Double y = 0.0;
						while (!stack.empty()) {
							y += (Double)stack.pop();
						}
						System.out.println("sum="+y);
						System.out.println(stack.getClass().getInterfaces()[0]);
		    			break;
		    		case Car:
		    			System.out.println("Car Test");
		    			for (int i = 0; i < m; i++) {
							Car car = new Car(in.nextInt(),in.next());
							System.out.println("push:"+stack.push(car));
						}
						for (int i = 0; i < n; i++) {
							System.out.println("pop:"+stack.pop());
						}
						System.out.println(stack.toString());
						while(!stack.empty()){
							System.out.println(((Car)stack.pop()).getName());
						}
						System.out.println(stack.getClass().getInterfaces()[0]);
						
						break;
		    			default:
		    				break;
		    		}
		    	}
		    	in.nextLine();
		    }
    }
}
